<template>
	<view class="content">
		<uni-search-bar @confirm="search" @cancel="cancel"/>
		<view class="none" v-if="datas.length == 0">暂无记录</view>
		<view class="list" v-else>
			<view class="exam-item1" v-for="(item, index) in datas" :key='index'>
				<view class="space">
					<view class="head-title">
						<text class="head-title-title">{{item.title}}</text><text class="sub">{{item.subject}}</text>
					</view>
				</view>
				<view>
					<view class="jilu-title">类型：{{item.type}}</view>
					<view class="jilu-title">开始时间：{{item.cratetime}}</view>
					<view class="jilu-title">完成时间：{{item.ehendtime}}</view>
				</view>
				<view class="anniu">
					<view @tap="pageChangeRep(item.selftest_log_id,item.type)" class="anniu-item baogao">查看报告</view>
					<view @tap="pageChangeMis(item.selftest_log_id)" class="anniu-item cuoti ">查看错题</view>
					<view @tap="pageChangeAna(item.selftest_log_id)" class="anniu-item jiexi ">试题解析</view>
				</view>
			</view>
		</view>
		<uni-load-more v-if="datas.length >= 6" :status="status" :content-text="contentText" />
	</view>
</template>

<script>
	import cDate from '@/common/util.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		data() {
			return {
				datas: [], // 遍历的数据项
				student_id: '',
				status: 'more',
				reload: true,
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				},
				page: 1
			}
		},
		components: {
			uniLoadMore
		},
		onPullDownRefresh() {
			this.reload = true;
			this.page=1;
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function(){
			_this.getList();
			},500);
		},
		onLoad(e) {
			this.student_id = e.student_id;
			// 开始请求
			this.getList();
		},
		methods: {
			/* 自评记录 */
			getList(value) {
				var data = {
					student_id: this.student_id,
					page: this.page,
					pagesize: 8
				}
				if(value) {
					data.title = value
				}
				this.$zapi.apiPost('user/selftest.users/SelfTestLists',data).then((res) => {
					if(res.data.code == 200) {
						let data = res.data.data.data;
						for(let i = 0; i < data.length; i++) {
							data[i].ehendtime = cDate.getFormatTime(data[i].update_time);
							data[i].cratetime = cDate.getFormatTime(data[i].crate_time);
							data[i].type = cDate.getKindName(data[i].test_type);
						}
						this.datas = this.reload ? data : this.datas.concat(data);
						this.reload = false;
						this.status = 'more';
					} else {
						if(this.reload){
							this.datas = [];
						}else{
							this.status='noMore';	
						}
					}
				})
			},
			/* 查看报告 */
			pageChangeRep(selftest_log_id,type) {
				uni.navigateTo({
					url: '../summary/report?selftest_log_id='+selftest_log_id+'&student_id='+this.student_id+'&type='+type
				})
			},
			/* 查看错题 */
			pageChangeMis(selftest_log_id) {
				uni.navigateTo({
					url: '../summary/wrong?selftest_log_id='+selftest_log_id+'&student_id='+this.student_id
				})
			},
			/* 查看解析 */
			pageChangeAna(selftest_log_id) {
				uni.navigateTo({
					url: '../summary/all?selftest_log_id='+selftest_log_id+'&student_id='+this.student_id
				})
			},
			// 搜索
			search(e) {
				this.page = 1;
				this.reload = true;
				this.getList(e.value);
			},
			// 取消搜索
			cancel() {
				this.page = 1;
				this.reload = true;
				this.getList();
			}
		}
	}
</script>

<style>
	html {
		font-size: 26upx;
	}

	.content {
		background: #EEEEEE;
		width: 100%;
	}
	.none{
		color: #999999;
		text-align: center;
		margin-top: 200upx;
	}
	.list{
		padding-top: 140upx;
	}
	.exam-item1 {
		width: calc(100% - 60upx);
		padding: 0 30upx;
		height: 424upx;
		background: #FFFFFF;
		margin-top: 10upx;
	}

	.space {
		position: relative;
		display: flex;
		/* height: 100upx; */
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		border-bottom: 2upx solid #E5E5E5;
	}
	
	.head-title {
		width: 100%;
		font-size: 36upx;
		font-weight: bold;
		align-items: center;
		color: #333333;
	}
	/* 内容溢出样式 */
	.head-title-title{
		display: inline-block;
		max-width: 80%;
		padding: 10upx 0;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		vertical-align: bottom;
	}
	.sub{
		position: absolute;
		top: 0;
		bottom: 0;
		height: 38upx;
		line-height: 38upx;
		margin: auto;
		font-size: 32upx;
		margin-left: 10upx;
		border-radius: 8upx;
		text-align: center;
		color: #FFFFFF;
		background: #00ACFE;
	}
	.jilu-title{
		height: 70upx;
		align-items: center;
		font-size: 34upx;
		color: #666666;
	}
	.jilu-title:last-child{
		border-bottom: 2upx solid #E5E5E5;
	}

	.anniu {
		display: flex;
		justify-content: flex-end;
	}

	.anniu-item {
		line-height: 1;
		padding: 14upx 26upx;
		color: #FFFFFF;
		display: flex;
		justify-content: flex-end;
		margin-left: 18upx;
		margin-top: 26upx;
	}

	.baogao {
		background: #00D555;
	}

	.cuoti {
		background: #FF9000;
	}

	.jiexi {
		background: #00ACFE;
	}
</style>
